class PostsController < ApplicationController

  def index
    @posts = Post.published.order(published_at: :desc).includes(:category).page params[:page]
  end

  def show
    @post = Post.where(slug: params[:slug]).first
    raise ActiveRecord::RecordNotFound.new "Missing post: #{params[:slug]}" if @post.blank?
  end

  def categorized
    @category = Category.where(slug: params[:category_slug]).first
    raise ActiveRecord::RecordNotFound.new "Missing category: #{params[:category_slug]}" if @category.blank?
    @posts = @category.posts.published.order(published_at: :desc).page params[:page]
  end
end
